#!/usr/bin/env php
<?php

# Script to generate log entries.

srand();

$agents = array(
  'Firefox',
  'Firefox',
  'Firefox',
  'Firefox',
  'IE',
  'IE',
  'IE',
  'Chrome',
  'Chrome',
  'Opera'
);

$pages = array(
  '"GET /"',
  '"GET /"',
  '"GET /"',
  '"GET /images/header.png"',
  '"GET /images/logo.png"',
  '"GET /menu.pdf"'
);

$client = new GearmanClient();
$client->addServer('127.0.0.1', 4730);

$time = time();

for ($x = 0; $x < 1000; $x++)
{
  # Batch 10 tasks at a time to speed inserts up.
  for ($y = 0; $y < 100; $y++)
  {
    $time += rand(0, 3);
    $log_entry = strftime('%c: ', $time);
    $ip = chr(rand(0, 127)) . chr(rand(0, 127)) .
          chr(rand(0, 127)) . chr(rand(0, 127));
    $log_entry .= inet_ntop($ip) . ' ';
    $log_entry .= $pages[rand(0, count($pages) - 1)] . ' ';
    $log_entry .= $agents[rand(0, count($agents) - 1)] . "\n";
    $client->addTaskBackground('log_collect', $log_entry);
  }

  $client->runTasks();
}

?>
